﻿@model List<Doan.Website.Models.Ask> 
@using Ext.Net
@using Ext.Net.MVC
@{
    ViewBag.Title = "ListQuestion";
    Layout = "~/Views/Shared/_Layout_Admin.cshtml";
}

@section Header
{
    <script type="text/javascript">
        function deleteItem(id) {
            var bt = confirm('Bạn có chắc chắn xóa đối tượng này?');
            if (bt == true) {
                App.direct.DeleteQuestion(id);
            }
        }
    </script>
}
@section ToolbarSection{
    @Html.X().Button().Text("Tạo mới").Icon(Icon.ControlAddBlue).Listeners(ls => ls.Click.Handler = "showWindow('Create Question','/Question/CreateQuestion',true,1,1);")
}
@* GridPanel *@

@(Html.X().GridPanel().ID("DataGridPanelQuestion")
        .Title("List Question")
        .Icon(Icon.Table)
        .Frame(true)
        .TopBar(Html.X().Toolbar().ID("ToolID").Items(items =>
         {
             items.Add(new LinkButton { Text = "All", Handler = "#{DirectMethods}.CharFilterQuestion('');", });

             items.Add(new ToolbarSpacer());
             items.Add(new ToolbarSeparator());
             items.Add(new ToolbarSpacer());

             items.Add(new LinkButton { Text = "0-9", Handler = "#{DirectMethods}.CharFilterQuestion('0');", });

             items.Add(new ToolbarSpacer());
             items.Add(new ToolbarSeparator());
             items.Add(new ToolbarSpacer());

             items.Add(new LinkButton { Text = "A", Handler = "#{DirectMethods}.CharFilterQuestion('A');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "B", Handler = "#{DirectMethods}.CharFilterQuestion('B');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "C", Handler = "#{DirectMethods}.CharFilterQuestion('C');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "D", Handler = "#{DirectMethods}.CharFilterQuestion('D');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "E", Handler = "#{DirectMethods}.CharFilterQuestion('E');", });
             items.Add(new ToolbarSpacer());

             items.Add(new ToolbarSpacer());
             items.Add(new ToolbarSeparator());
             items.Add(new ToolbarSpacer());

             items.Add(new LinkButton { Text = "F", Handler = "#{DirectMethods}.CharFilterQuestion('F');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "G", Handler = "#{DirectMethods}.CharFilterQuestion('G');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "H", Handler = "#{DirectMethods}.CharFilterQuestion('H');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "I", Handler = "#{DirectMethods}.CharFilterQuestion('I');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "J", Handler = "#{DirectMethods}.CharFilterQuestion('J');", });
             items.Add(new ToolbarSpacer());

             items.Add(new ToolbarSpacer());
             items.Add(new ToolbarSeparator());
             items.Add(new ToolbarSpacer());

             items.Add(new LinkButton { Text = "K", Handler = "#{DirectMethods}.CharFilterQuestion('K');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "L", Handler = "#{DirectMethods}.CharFilterQuestion('L');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "M", Handler = "#{DirectMethods}.CharFilterQuestion('M');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "N", Handler = "#{DirectMethods}.CharFilterQuestion('N');", });
             items.Add(new ToolbarSpacer());

             items.Add(new ToolbarSpacer());
             items.Add(new ToolbarSeparator());
             items.Add(new ToolbarSpacer());

             items.Add(new LinkButton { Text = "O", Handler = "#{DirectMethods}.CharFilterQuestion('O');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "P", Handler = "#{DirectMethods}.CharFilterQuestion('P');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "Q", Handler = "#{DirectMethods}.CharFilterQuestion('Q');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "R", Handler = "#{DirectMethods}.CharFilterQuestion('R');", });
             items.Add(new ToolbarSpacer());

             items.Add(new ToolbarSpacer());
             items.Add(new ToolbarSeparator());
             items.Add(new ToolbarSpacer());

             items.Add(new LinkButton { Text = "S", Handler = "#{DirectMethods}.CharFilterQuestion('S');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "T", Handler = "#{DirectMethods}.CharFilterQuestion('T');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "U", Handler = "#{DirectMethods}.CharFilterQuestion('U');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "V", Handler = "#{DirectMethods}.CharFilterQuestion('V');", });
             items.Add(new ToolbarSpacer());

             items.Add(new ToolbarSpacer());
             items.Add(new ToolbarSeparator());
             items.Add(new ToolbarSpacer());

             items.Add(new LinkButton { Text = "W", Handler = "#{DirectMethods}.CharFilterQuestion('W');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "X", Handler = "#{DirectMethods}.CharFilterQuestion('X');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "Y", Handler = "#{DirectMethods}.CharFilterQuestion('Y');", });
             items.Add(new ToolbarSpacer());
             items.Add(new LinkButton { Text = "Z", Handler = "#{DirectMethods}.CharFilterQuestion('Z');", });
             items.Add(new ToolbarSpacer());

             items.Add(new ToolbarFill());
             
             items.Add(new Checkbox
             {
                 FieldLabel = "Gồm cả bản ghi đã xóa",
                 Margins = "0 0 0 10",
                 LabelWidth = 230,
                 DirectCheckAction = "IncludeInActive"
             });
         }))

        .Store(Html.X().Store().ID("QuestionStore")
            .Model(Html.X().Model().IDProperty("QuestionId")
                .Fields(
                    new ModelField("AskId", ModelFieldType.Int),
                    new ModelField("Content", ModelFieldType.String),
                    new ModelField("CreateDate", ModelFieldType.Date),
                    new ModelField("Title", ModelFieldType.String),
                    new ModelField("GNName", ModelFieldType.String),
                    new ModelField("AuthorName", ModelFieldType.String),
                    new ModelField("Email", ModelFieldType.String),
                    new ModelField("Active", ModelFieldType.Boolean)
                )
            )
                .RemoteSort(true)
                .RemotePaging(true)
                .PageSize(15)
                    .Proxy(Html.X().AjaxProxy().Url(Url.Action("BindingQuestionStore"))
                                .Reader(Html.X().JsonReader().Root("data")))
        )
        .ColumnModel(
                    Html.X().Column().Text("Tựa đề").DataIndex("Title").Flex(1),
                    Html.X().Column().Text("Nội dung").DataIndex("Content").Flex(1),
                    Html.X().Column().Text("Ngày tạo").DataIndex("CreateDate").Flex(1),
                    Html.X().Column().Text("Nhóm").DataIndex("GNName").Flex(1),
                    Html.X().Column().Text("Người tạo").DataIndex("AuthorName").Flex(1),
                    Html.X().Column().Text("Email").DataIndex("Email").Flex(1),  
                    Html.X().Column().Text("Trạng thái kích hoạt").DataIndex("Active").Flex(1),
                    Html.X().CommandColumn().Width(60).Commands(
                        Html.X().GridCommand().CommandName("Edit").Icon(Icon.NoteEdit).Text("Sửa")
                    ).Listeners(ls => ls.Command.Handler = "showWindow('Edit Question', '/Question/EditQuestion/' + record.data.AskId, true, 1, 1);"),
                    Html.X().CommandColumn().Width(60).Commands(
                        Html.X().GridCommand().CommandName("Answer").Icon(Icon.ApplicationGo).Text("Trả lời")
                    ).Listeners(ls => ls.Command.Handler = "showWindow('Edit Answer', '/Answer/EditAnswer/' + record.data.AskId, true, 1, 1);"),
                    Html.X().CommandColumn().Width(60).Commands(Html.X().GridCommand().CommandName("Edit").Icon(Icon.Delete).Text("Xóa"))
                            .Listeners(ls => ls.Command.Handler = "deleteItem(record.data.AskId);")
        )
        .SelectionModel(Html.X().CheckboxSelectionModel().RowSpan(1))
        .BottomBar(Html.X().PagingToolbar())
)
